# Contributor: Adrian Siekierka <kontakt@asie.pl>
# Maintainer: Thomas Kienlen <kommander@laposte.net>
pkgname=openttd
pkgver=13.4
pkgrel=1
pkgdesc="Open source version of the Transport Tycoon Deluxe simulator"
url="https://www.openttd.org"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	cmake
	fontconfig-dev
	fluidsynth-dev
	freetype-dev
	icu-dev
	libpng-dev
	lzo-dev
	samurai
	sdl2-dev
	xz-dev
	zlib-dev
	"
subpackages="$pkgname-doc $pkgname-lang::noarch"
source="https://cdn.openttd.org/openttd-releases/$pkgver/openttd-$pkgver-source.tar.xz
	no-sse4.patch
	"
options="!check" # TODO: find how to start test suite, no check implemented

build() {
	cmake -B build \
		-G "Ninja" \
		-DCMAKE_INSTALL_BINDIR=bin \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_DATADIR=share/games \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS -Wl,-z,stack-size=1048576"
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
}

lang() {
	pkgdesc="$pkgdesc (localizations)"

	cd "$pkgdir"
	mkdir -p "$subpkgdir"/usr/share/games/openttd/lang
	find usr/share/games/openttd/lang/ ! -name 'english.lng' -type f \
		-exec mv {} "$subpkgdir"/{} \;
}

sha512sums="
84f57a39c0dade44f0e6153dff7a40eec0da8e2f892ce870d5f9e037f80daa5c7c46ff786fa51c3671366dd5056504cd7ccbc1c4e5bce8b2c5575533b454c001  openttd-13.4-source.tar.xz
fef70a685b4d440a0c1a6b6cde94df2dcada7ee10f4b213ee0a649dfbbb5de800aed06a4f066b2be5369147b1ecd83ad6b89bdb06138c46b250ca7f75c95b5a4  no-sse4.patch
"
